package com.xyj.action.base;

import com.alibaba.fastjson.JSON;
import com.xyj.util.LoggerUtil;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import sun.rmi.runtime.Log;

import java.io.IOException;

/**
 * Created by 徐宇健 on 2015/2/11 0011.
 */
@ParentPackage("basePackage")
@Namespace("/")
public class BaseAction {

    public  void writeJson(Object o){

        try {
            ServletActionContext.getResponse().setCharacterEncoding("utf-8");
            ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
            String json = JSON.toJSONStringWithDateFormat(o,"yyyy-MM-dd HH:mm:ss");
            LoggerUtil.getLogger().info("json>>>>>"+json);
            ServletActionContext.getResponse().getWriter().write(json);
            ServletActionContext.getResponse().getWriter().flush();
            ServletActionContext.getResponse().getWriter().close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
